package modelo;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Scanner;

import controlador.Jugador;
import android.app.Activity;
import android.content.Context;

public class Binario_DAO {

	public void grabar(Activity ma, Jugador j) {
		
		
		String jugador = j.getNombre() + "         " + j.getVictorias() + "\n";


		try {
			FileOutputStream fos;
			fos = ma.openFileOutput("puntuaciones_bi.txt", Context.MODE_APPEND);
			fos.write(jugador.getBytes());
			fos.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	public ArrayList<String> mostrar(Activity ma) {
		ArrayList<String> datos = new 	ArrayList<String>();
		byte[] dato = new byte[1024];
		
		FileInputStream fis;
		String str = "";
		try {
			fis = ma.openFileInput("puntuaciones_bi.txt");
			while (fis.read(dato) != -1) {
				str = str + new String(dato);
			}
			fis.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	
		String[] arrayStr = str.split("\n");
		for(int i = 0; i < arrayStr.length ; i ++){
			datos.add(arrayStr[i]);
		}
		
	
		return datos;
	}

}
